package com.bjpowernode.web.controller;

import com.bjpowernode.commons.model.User;
import com.bjpowernode.commons.service.AccountService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("account")
@CrossOrigin
public class AccountController {
    @DubboReference
    private AccountService accountService;

    @Resource
    private RedisTemplate redisTemplate;

    @GetMapping("balance")
    public Double getBalance(@RequestHeader(value = "token", required = false) String token) {
        User user = (User) redisTemplate.opsForValue().get(token);
        return accountService.getBalance(user.getId());
    }
}
